import { createStore } from "vuex";

const store = createStore({
  state: {
    money: 10000,
  },

  //   同步处理
  mutations: {
    addMoney(state, val) {
      state.money += val;
    },
  },

  //   异步处理
  actions: {
    addMoneyAsync(context, val) {
      setTimeout(() => {
        context.commit("addMoney", val);
      }, 1000);
    },
  },
  getters: {
    double(state) {
      return state.money * 2;
    },
  },
});

export default store;
